/*
  Copyright (c) 2009-10 by kRaw1er & HierOS
  This file is part of M8J project
*/
#include "CChangeStatusWnd.h"

CChangeStatusWnd::CChangeStatusWnd(void)
:	m_Presence(PresenceUnknown),
	m_PresenceMessage("")
{
}

CChangeStatusWnd::~CChangeStatusWnd(void)
{
}

BOOL CChangeStatusWnd::OnInitDialog()
{
	if (!CMzWndEx::OnInitDialog())
	{
		return FALSE;
	}

	m_ScrollWin.SetPos(0, 0, GetWidth(), GetHeight() - MZM_HEIGHT_TEXT_TOOLBAR);
	m_ScrollWin.EnableScrollBarV(true);
	AddUiWin(&m_ScrollWin);

	int y = 0;
	m_StatusAvailable.SetID(MZ_IDC_STATUS_AVAILABLE);
	m_StatusAvailable.SetPos(0, y, GetWidth(), MZM_HEIGHT_BUTTONEX);
	m_StatusAvailable.SetButtonType(MZC_BUTTON_LINE_TOPBOTTOM);
	m_StatusAvailable.SetImage1(&IMG_ONLINE);
	m_StatusAvailable.SetImageWidth1(IMG_ONLINE.GetImageWidth());
	m_StatusAvailable.SetShowImage1(true);
	m_StatusAvailable.SetText(STR_PRESENCE_AVAILABLE_TITLE.c_str());
	m_StatusAvailable.SetTextMaxLen(GetWidth());
	m_ScrollWin.AddChild(&m_StatusAvailable);

	y += MZM_HEIGHT_BUTTONEX;
	m_StatusUnavailable.SetID(MZ_IDC_STATUS_UNAVAILABLE);
	m_StatusUnavailable.SetPos(0, y, GetWidth(), MZM_HEIGHT_BUTTONEX);
	m_StatusUnavailable.SetButtonType(MZC_BUTTON_LINE_BOTTOM);
	m_StatusUnavailable.SetImage1(&IMG_OFFLINE);
	m_StatusUnavailable.SetImageWidth1(IMG_OFFLINE.GetImageWidth());
	m_StatusUnavailable.SetShowImage1(true);
	m_StatusUnavailable.SetText(STR_PRESENCE_UNAVAILABLE_TITLE.c_str());
	m_StatusUnavailable.SetTextMaxLen(GetWidth());
	m_ScrollWin.AddChild(&m_StatusUnavailable);

	y += MZM_HEIGHT_BUTTONEX;
	m_StatusChat.SetID(MZ_IDC_STATUS_CHAT);
	m_StatusChat.SetPos(0, y, GetWidth(), MZM_HEIGHT_BUTTONEX);
	m_StatusChat.SetButtonType(MZC_BUTTON_LINE_BOTTOM);
	m_StatusChat.SetImage1(&IMG_FFC);
	m_StatusChat.SetImageWidth1(IMG_FFC.GetImageWidth());
	m_StatusChat.SetShowImage1(true);
	m_StatusChat.SetText(STR_PRESENCE_CHAT_TITLE.c_str());
	m_StatusChat.SetTextMaxLen(GetWidth());
	m_ScrollWin.AddChild(&m_StatusChat);

	y += MZM_HEIGHT_BUTTONEX;
	m_StatusAway.SetID(MZ_IDC_STATUS_AWAY);
	m_StatusAway.SetPos(0, y, GetWidth(), MZM_HEIGHT_BUTTONEX);
	m_StatusAway.SetButtonType(MZC_BUTTON_LINE_BOTTOM);
	m_StatusAway.SetImage1(&IMG_AWAY);
	m_StatusAway.SetImageWidth1(IMG_AWAY.GetImageWidth());
	m_StatusAway.SetShowImage1(true);
	m_StatusAway.SetText(STR_PRESENCE_AWAY_TITLE.c_str());
	m_StatusAway.SetTextMaxLen(GetWidth());
	m_ScrollWin.AddChild(&m_StatusAway);

	y += MZM_HEIGHT_BUTTONEX;
	m_StatusXa.SetID(MZ_IDC_STATUS_XA);
	m_StatusXa.SetPos(0, y, GetWidth(), MZM_HEIGHT_BUTTONEX);
	m_StatusXa.SetButtonType(MZC_BUTTON_LINE_BOTTOM);
	m_StatusXa.SetImage1(&IMG_XA);
	m_StatusXa.SetImageWidth1(IMG_XA.GetImageWidth());
	m_StatusXa.SetShowImage1(true);
	m_StatusXa.SetText(STR_PRESENCE_XA_TITLE.c_str());
	m_StatusXa.SetTextMaxLen(GetWidth());
	m_ScrollWin.AddChild(&m_StatusXa);

	y += MZM_HEIGHT_BUTTONEX;
	m_StatusDnd.SetID(MZ_IDC_STATUS_DND);
	m_StatusDnd.SetPos(0, y, GetWidth(), MZM_HEIGHT_BUTTONEX);
	m_StatusDnd.SetButtonType(MZC_BUTTON_LINE_BOTTOM);
	m_StatusDnd.SetImage1(&IMG_DND);
	m_StatusDnd.SetImageWidth1(IMG_DND.GetImageWidth());
	m_StatusDnd.SetShowImage1(true);
	m_StatusDnd.SetText(STR_PRESENCE_DND_TITLE.c_str());
	m_StatusDnd.SetTextMaxLen(GetWidth());
	m_ScrollWin.AddChild(&m_StatusDnd);

	m_Toolbar.SetID(MZ_IDC_TOOLBAR);
	m_Toolbar.SetPos(0, GetHeight() - MZM_HEIGHT_TEXT_TOOLBAR, GetWidth(), MZM_HEIGHT_TEXT_TOOLBAR);
	m_Toolbar.SetButton(2, true, true, STR_BACK.c_str());
	AddUiWin(&m_Toolbar);

	return TRUE;
}

void CChangeStatusWnd::OnMzCommand(WPARAM wParam, LPARAM lParam)
{
	RECT rc;
	CInputWnd * dlg = new CInputWnd;
	switch(LOWORD(wParam))
	{
	case MZ_IDC_STATUS_AVAILABLE:
		m_Presence = PresenceAvailable;
		EndModal(1);
		break;

	case MZ_IDC_STATUS_UNAVAILABLE:
		m_Presence = PresenceUnavailable;
		EndModal(1);
		break;

	case MZ_IDC_STATUS_AWAY:
		m_Presence = PresenceAway;
		rc = MzGetWorkArea();
		dlg->Create(rc.left, rc.top, RECT_WIDTH(rc), RECT_HEIGHT(rc), m_hWnd, 0, WS_POPUP);
		dlg->SetAnimateType_Show(MZ_ANIMTYPE_FADE);
		dlg->SetAnimateType_Hide(MZ_ANIMTYPE_FADE);
		if (dlg->DoModal() == 1);
		{
			m_PresenceMessage = toUTF8(dlg->m_Edit.GetText().C_Str());
		}
		EndModal(1);
		break;

	case MZ_IDC_STATUS_CHAT:
		m_Presence = PresenceChat;
		rc = MzGetWorkArea();
		dlg->Create(rc.left, rc.top, RECT_WIDTH(rc), RECT_HEIGHT(rc), m_hWnd, 0, WS_POPUP);
		dlg->SetAnimateType_Show(MZ_ANIMTYPE_FADE);
		dlg->SetAnimateType_Hide(MZ_ANIMTYPE_FADE);
		if (dlg->DoModal() == 1);
		{
			m_PresenceMessage = toUTF8(dlg->m_Edit.GetText().C_Str());
		}
		EndModal(1);
		break;

	case MZ_IDC_STATUS_DND:
		m_Presence = PresenceDnd;
		rc = MzGetWorkArea();
		dlg->Create(rc.left, rc.top, RECT_WIDTH(rc), RECT_HEIGHT(rc), m_hWnd, 0, WS_POPUP);
		dlg->SetAnimateType_Show(MZ_ANIMTYPE_FADE);
		dlg->SetAnimateType_Hide(MZ_ANIMTYPE_FADE);
		if (dlg->DoModal() == 1);
		{
			m_PresenceMessage = toUTF8(dlg->m_Edit.GetText().C_Str());
		}
		EndModal(1);
		break;

	case MZ_IDC_STATUS_XA:
		m_Presence = PresenceXa;
		rc = MzGetWorkArea();
		dlg->Create(rc.left, rc.top, RECT_WIDTH(rc), RECT_HEIGHT(rc), m_hWnd, 0, WS_POPUP);
		dlg->SetAnimateType_Show(MZ_ANIMTYPE_FADE);
		dlg->SetAnimateType_Hide(MZ_ANIMTYPE_FADE);
		if (dlg->DoModal() == 1);
		{
			m_PresenceMessage = toUTF8(dlg->m_Edit.GetText().C_Str());
		}
		EndModal(1);
		break;

	case MZ_IDC_TOOLBAR:
		if (lParam == 2)
		{
			EndModal(0);
		}
		break;
	}
	delete dlg;
	dlg = NULL;
}
